package com.example.lib;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

import android.app.Activity;
/* Developer : Park Ju Yong */
public class FileCopy {
	public void copyDB(String location, String file, Activity activity) {
		boolean exists = (new File(location + file)).exists();
		if (exists == true)	{
			return ;
		}		
		
		File f = new File(location);
		f.mkdirs();

		InputStream myInput = null;
		try {
			myInput = activity.getAssets().open("data/" + file);
		} catch (IOException e) {
			//Log.e("copyDB", "getAssets Failed");
			e.printStackTrace();
		}

		FileOutputStream myOutput = null;
		try {
			myOutput = new FileOutputStream(location + file, false);
		} catch (FileNotFoundException e) {
			//Log.e("copyDB", "FileOutputStream Failed");
			e.printStackTrace();
		}

		byte[] buffer = new byte[1024];
		int length;
		try {
			while ((length = myInput.read(buffer)) > 0) {
				if (file.equals(StaticVariable.g_DBName)) {					
				}
				myOutput.write(buffer, 0, length);
			}
		} catch (IOException e) {
			//Log.e("copyDB", "Write Failed");
			e.printStackTrace();
		}
		try {
			myOutput.flush();
		} catch (IOException e) {
			//Log.e("copyDB", "Output flush Failed");
			e.printStackTrace();
		}
		try {
			myOutput.close();
		} catch (IOException e) {
			//Log.e("copyDB", "Output close Failed");
			e.printStackTrace();
		}
		try {
			myInput.close();
		} catch (IOException e) {
			//Log.e("copyDB", "Input flush Failed");
			e.printStackTrace();
		}	
	}
}

			

